cmake_minimum_required(VERSION 3.10.2)
project(remote)
cmake_policy(SET CMP0072 NEW)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(cmake_policy CMP0046 NEW)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_BUILD_TYPE "RELEASE")
find_package(catkin REQUIRED COMPONENTS roscpp rospy sensor_msgs std_msgs std_srvs tf
    tf2 tf2_ros tf2_geometry_msgs geometry_msgs dynamic_reconfigure rosbag)
find_package(Eigen3 QUIET)
find_package(yaml-cpp REQUIRED)
find_package(OpenCV REQUIRED)
find_package(Threads REQUIRED)
find_package(cartographer REQUIRED)
find_package(Boost REQUIRED COMPONENTS system iostreams serialization)
find_package(Qt5 COMPONENTS Core Widgets OpenGL Concurrent REQUIRED)
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL REQUIRED)
find_package(GLOG REQUIRED)
set(CMAKE_PREFIX_PATH "/opt/ikitrobot/sysroot/lib/cmake")
message("CMAKE_PREFIX_PATH = ${CMAKE_PREFIX_PATH}")
find_package(absl REQUIRED)
if(NOT absl_FOUND)
    message(FATAL_ERROR "Abseil library not found!")
endif()
catkin_package(CATKIN_DEPENDS roscpp)
file(GLOB_RECURSE ALL_PROTOS "proto/*.proto")
set(ALL_PROTO_SRCS)
set(ALL_PROTO_HDRS)
foreach(ABS_FIL ${ALL_PROTOS})
    message("Proto file:(${ABS_FIL})")
    file(RELATIVE_PATH REL_FIL ${PROJECT_SOURCE_DIR} ${ABS_FIL})
    get_filename_component(DIR ${REL_FIL} DIRECTORY)
    get_filename_component(FIL_WE ${REL_FIL} NAME_WE)
    list(APPEND ALL_PROTO_SRCS "${PROJECT_BINARY_DIR}/${DIR}/${FIL_WE}.pb.cc")
    list(APPEND ALL_PROTO_HDRS "${PROJECT_BINARY_DIR}/${DIR}/${FIL_WE}.pb.h")
    add_custom_command(
        OUTPUT "${PROJECT_BINARY_DIR}/${DIR}/${FIL_WE}.pb.cc"
            "${PROJECT_BINARY_DIR}/${DIR}/${FIL_WE}.pb.h"
        COMMAND  ${PROTOBUF_PROTOC_EXECUTABLE}
        ARGS --cpp_out  ${PROJECT_BINARY_DIR} -I
            ${PROJECT_SOURCE_DIR} ${ABS_FIL}
        DEPENDS ${ABS_FIL}
        COMMENT "Running C++ protocol buffer compiler on ${ABS_FIL}"
        VERBATIM
    )
endforeach()
set_source_files_properties(${ALL_PROTO_SRCS} ${ALL_PROTO_HDRS} PROPERTIES GENERATED TRUE)
list(APPEND ALL_LIBRARY_HDRS ${ALL_PROTO_HDRS})
list(APPEND ALL_LIBRARY_SRCS ${ALL_PROTO_SRCS})
set(INSTALL_GENERATED_HDRS ${ALL_PROTO_HDRS})
include_directories(include ${catkin_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/src 
    "/opt/ros/${ROS_DISTRO}/include" "/opt/ikitrobot/sysroot/include"
)
file(GLOB_RECURSE SRCS "src/*.cpp")
list(REMOVE_ITEM SRCS "${CMAKE_CURRENT_SOURCE_DIR}/src/ros_visualizer.cpp")
list(REMOVE_ITEM SRCS "${CMAKE_CURRENT_SOURCE_DIR}/src/mainwindow_clean.cpp")
qt5_wrap_cpp(MOC_SRCS 
    src/mainwindow.hpp
    src/remote_widget.hpp
    src/player_widget.hpp
    src/edit_widget.hpp
)
add_executable(${PROJECT_NAME}_node ${SRCS} ${MOC_SRCS})
target_link_libraries(${PROJECT_NAME}_node PUBLIC
    cartographer
    Boost::iostreams Boost::serialization 
    ${catkin_LIBRARIES} ${EIGEN3_LIBRARIES} ${Boost_LIBRARIES} 
    glog
    gflags
    jpeg yaml-cpp Threads::Threads Qt5::Widgets Qt5::OpenGL Qt5::Concurrent ${OPENGL_LIBRARIES}
    ${OpenCV_LIBS} 
    absl::algorithm
    absl::base
    absl::debugging
    absl::flat_hash_map
    absl::memory
    absl::meta
    absl::numeric
    absl::str_format
    absl::strings
    absl::synchronization
    absl::time
    absl::utility 
)
install(TARGETS ${PROJECT_NAME}_node
    RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
    ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
    LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
)
install(DIRECTORY launch/
    DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)